class Hobby:
    def __init__(self,name):
        self.name = name
        self.num = 0
    # 被print方法调用
    def __str__(self):
        return f'my hobby is {self.name}'
    
    # 被for in 调用
    def __iter__(self):
        return self # 实例本身就是迭代对象，故返回自己

    def __next__(self):
        self.num +=1
        if self.num > 5: # 退出循环的条件
            raise StopIteration()
        return self.num # 返回下一个值
    # [1]下标取值调用
    def __getitem__(self,n):
        return n
    
c1 =  Hobby('唱、跳、rap、打篮球')
print(c1)

for item in c1:
    print(item)

print(c1[1])